package GUI.Cliente;

import java.rmi.RemoteException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import service.article.exceptions.ProxyException;

public class MenuCliente extends Shell {

	/**
	 * Launch the application.
	 * @param args
	 */
	static MenuCliente shell;
	public static void main(String args[]) {
		try {
			Display display = Display.getDefault();
			shell = new MenuCliente(display);
			shell.open();
			shell.layout();
			while (!shell.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the shell.
	 * @param display
	 */
	public MenuCliente(Display display) {
		super(display, SWT.SHELL_TRIM);
		setLayout(new FormLayout());
		
		Button btnVerListadoDe = new Button(this, SWT.NONE);
		btnVerListadoDe.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			VerClientesLista a = new VerClientesLista (shell, shell.getStyle());
			shell.setVisible(false);
			try {
				a.open();
			} catch (RemoteException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (ProxyException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			}
		});
		FormData fd_btnVerListadoDe = new FormData();
		fd_btnVerListadoDe.left = new FormAttachment(0, 107);
		fd_btnVerListadoDe.right = new FormAttachment(100, -107);
		btnVerListadoDe.setLayoutData(fd_btnVerListadoDe);
		btnVerListadoDe.setText("Ver Listado De Clientes");
		
		final Button btnBuscarClienteEn = new Button(this, SWT.NONE);
		btnBuscarClienteEn.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

				BuscarClienteCedula b = new BuscarClienteCedula (shell, shell.getStyle(),0);
				b.open();
				
			}
		});
		FormData fd_btnBuscarClienteEn = new FormData();
		fd_btnBuscarClienteEn.top = new FormAttachment(btnVerListadoDe, 6);
		fd_btnBuscarClienteEn.left = new FormAttachment(btnVerListadoDe, 0, SWT.LEFT);
		fd_btnBuscarClienteEn.right = new FormAttachment(100, -107);
		btnBuscarClienteEn.setLayoutData(fd_btnBuscarClienteEn);
		btnBuscarClienteEn.setText("Buscar Cliente en la Base de Datos");
		
		Button btnModificarInformacionDe = new Button(this, SWT.NONE);
		btnModificarInformacionDe.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				BuscarClienteCedula b = new BuscarClienteCedula (shell, shell.getStyle(),1);
				b.open();
			}
		});
		FormData fd_btnModificarInformacionDe = new FormData();
		fd_btnModificarInformacionDe.top = new FormAttachment(btnBuscarClienteEn, 17);
		fd_btnModificarInformacionDe.left = new FormAttachment(btnVerListadoDe, 0, SWT.LEFT);
		fd_btnModificarInformacionDe.right = new FormAttachment(100, -107);
		btnModificarInformacionDe.setLayoutData(fd_btnModificarInformacionDe);
		btnModificarInformacionDe.setText("Modificar Informacion de un Cliente");
		
		Button btnEliminarClienteDe = new Button(this, SWT.NONE);
		btnEliminarClienteDe.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				BuscarClienteCedula b = new BuscarClienteCedula (shell, shell.getStyle(),2);
				b.open();
				
			}
		});
		FormData fd_btnEliminarClienteDe = new FormData();
		fd_btnEliminarClienteDe.top = new FormAttachment(btnModificarInformacionDe, 6);
		fd_btnEliminarClienteDe.left = new FormAttachment(btnVerListadoDe, 0, SWT.LEFT);
		fd_btnEliminarClienteDe.right = new FormAttachment(100, -107);
		btnEliminarClienteDe.setLayoutData(fd_btnEliminarClienteDe);
		btnEliminarClienteDe.setText("Eliminar Cliente de la Base de Datos");
		
		Label lblEligaLaOpcion = new Label(this, SWT.NONE);
		FormData fd_lblEligaLaOpcion = new FormData();
		fd_lblEligaLaOpcion.top = new FormAttachment(0, 17);
		fd_lblEligaLaOpcion.left = new FormAttachment(0, 117);
		fd_lblEligaLaOpcion.right = new FormAttachment(0, 333);
		lblEligaLaOpcion.setLayoutData(fd_lblEligaLaOpcion);
		lblEligaLaOpcion.setAlignment(SWT.CENTER);
		lblEligaLaOpcion.setText("Eliga La Opcion Deseada");
		
		Button btnAgregarCliente = new Button(this, SWT.NONE);
		fd_btnVerListadoDe.top = new FormAttachment(btnAgregarCliente, 6);
		btnAgregarCliente.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				AddClient a = new AddClient (shell,  shell.getStyle());
				shell.setVisible(false);
				a.open();
			}
		});
		FormData fd_btnAgregarCliente = new FormData();
		fd_btnAgregarCliente.left = new FormAttachment(0, 107);
		fd_btnAgregarCliente.right = new FormAttachment(100, -107);
		fd_btnAgregarCliente.top = new FormAttachment(lblEligaLaOpcion, 18);
		btnAgregarCliente.setLayoutData(fd_btnAgregarCliente);
		btnAgregarCliente.setText("Agregar Cliente");
		createContents();
	}

	/**
	 * Create contents of the shell.
	 */
	protected void createContents() {
		setText("Clientes");
		setSize(450, 300);

	}

	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}

}
